<extend name="Layout/ins_page" />
<block name="content">
	<input type="hidden" name="ajax" id="ajax" value="1">
	{:W('PageHeader/simple',array('name'=>'部门级别'))}
	<div class="oprator-panel">
		<div class="split"></div>
		<a id="btn_add" class="btn">新增</a>
		<a id="btn_save"  class="btn">保存</a>
		<span class="l">|</span>
		<a id="btn_del"  class="btn btn-del btn-del">删除</a>
	</div>
	<div class="sub-frame">
		<div class="sub-sidebar white">
			<table class="table table-bordered">
				<thead>
					<tr>
						<th>名称</th>
						<th>状态</th>
					</tr>
				</thead>
				<tbody>
					<volist name="list" id="data">
						<tr id="{$data.id}">
							<td>{$data.name}</td>
							<td>{$data.is_del|status}</td>
						</tr>
					</volist>
				</tbody>
			</table>
		</div>
		<div class="sub-content gray">
			<form id="form_data" name="form_data"method="post" >
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="opmode" id="opmode" value="">
				<input type="hidden" name="ajax" id="ajax" value="1">
				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="name">名称*：</label>
					<div class="layui-input-block col-16">
						<input class="layui-input"  type="text" id="name" name="name" check="required" info="请输入名称">
					</div>
				</div>

				<div class="layui-sub-form-item col-xs-12">
					<label class="layui-form-label" for="sort">排序：</label>
					<div class="layui-input-block col-10">
						<input class="layui-input"  type="text" id="sort" name="sort" >
					</div>
				</div>
				<div class="layui-sub-form-item col-xs-12">
					<label class="layui-form-label" for="is_del">状态：</label>
					<div class="layui-input-block col-10">
						<select  class="layui-input" name="is_del" id="is_del">
							<option  value="0">启用</option>
							<option value="1">禁用</option>
						</select>
					</div>
				</div>
			</form>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use(['global'], function() {
			var $ = layui.jquery;

			function showdata(result) {
				for (var s in result.data) {
					set_val(s, result.data[s]);
				}
				//console.log(result.data);
				$("#dept_name").val($("#dept_list option[value='" + $("#pid").val() + "']").text());
				$("#opmode").val("edit");
			};

			$("#btn_add").on('click', function() {
				winopen("{:U('add')}", 560, 470);
			});

			$("#btn_save").on('click', function() {
				send_form("form_data", "{:U('save')}", "{:U('index')}", function(ret) {
					if (ret.status) {
						layer.msg(ret.info, {
							time : 1200
						}, function() {
							location.reload(true);
						});
					}
				});
			});

			$('#select_pid').on('click', function() {
				winopen("{:U('winpop')}", 560, 470);
			});

			$('#btn_del').on('click', function() {
				if ($(".sub-sidebar tr.active").length == 0) {
					layer.msg('请选择要删除的部门级别');
					return false;
				}
				//信息框-例2
				layer.msg('确定要删除吗?', {
					time : 0,
					btn : ['确定', '取消'],
					yes : function(index) {
						var vars = $("#form_data").serialize();
						send_ajax("{:U('del')}", vars, function(ret) {
							if (ret.status) {
								layer.msg(ret.info, {
									time : 1200
								}, function() {
									location.reload(true);
								});
							}
						});
					},
					no : function(index) {
						layer.close(index);
					}
				});
			});

			$(".sub-sidebar tbody tr").click(function() {
				$(".sub-sidebar  tr.active").removeClass("active");
				$(this).attr("class", "active");
				send_ajax("{:U('read')}", "id=" + $(this).attr("id"), function(data) {
					showdata(data);
				});
				return false;
			});

			function showdata(result) {
				for (var s in result.data) {
					set_val(s, result.data[s]);
				}
				$("#opmode").val("edit");
			}

		});

	</script>
</block>